package com.kylexy.closes.ui.fragment;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;

import com.kylexy.closes.R;
import com.kylexy.closes.app.UIHelper;
import com.kylexy.closes.bean.MainMenu;
import com.kylexy.closes.tools.MenuUtil;
import com.kylexy.closes.ui.adapter.MainGridAdapter;
import com.kylexy.closes.widge.MyGridView;

public class FragmentMain extends Fragment {
	View _view;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		_view = inflater.inflate(R.layout.fragment_main, null);

		initTitle();

		initGrid1();
		initGrid2();
		initGrid3();
		initGrid4();

		return _view;
	}

	private void initTitle() {

		MenuUtil.setMenuBack(getActivity(), _view);
		MenuUtil.setMenuTitle(_view, "XXXX商店");

		MenuUtil.setMenuMore(getActivity(), _view, true, "设置",
				new OnClickListener() {

					@Override
					public void onClick(View arg0) {
						// TODO Auto-generated method stub

					}
				});
	}

	public void initGrid1() {

		MyGridView grid1 = (MyGridView) _view.findViewById(R.id.grid);

		final List<MainMenu> datas = new ArrayList<MainMenu>();
		datas.add(new MainMenu(11, "商品设置"));

		MainGridAdapter mAdapter = new MainGridAdapter(getActivity(), datas);
		// grid1.setColumnCount(4);

		grid1.setAdapter(mAdapter);
		grid1.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				// TODO Auto-generated method stub
				MainMenu menu = datas.get(arg2);
				UIHelper.startActivitys(getActivity(), menu);

			}
		});

	}

	public void initGrid2() {

		GridView grid1 = (GridView) _view.findViewById(R.id.grid2);

		final List<MainMenu> datas = new ArrayList<MainMenu>();
		datas.add(new MainMenu(21, "商品进货"));
		datas.add(new MainMenu(22, "商品出货"));
		datas.add(new MainMenu(23, "单品销售"));

		MainGridAdapter mAdapter = new MainGridAdapter(getActivity(), datas);
		// grid1.setColumnCount(4);
		grid1.setAdapter(mAdapter);
		grid1.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				// TODO Auto-generated method stub
				MainMenu menu = datas.get(arg2);
				// UIHelper.startActivitys(getActivity(), menu);

			}
		});

	}

	public void initGrid3() {

		GridView grid1 = (GridView) _view.findViewById(R.id.grid3);

		final List<MainMenu> datas = new ArrayList<MainMenu>();
		datas.add(new MainMenu(21, "库存盘点"));

		MainGridAdapter mAdapter = new MainGridAdapter(getActivity(), datas);
		// grid1.setColumnCount(4);
		grid1.setAdapter(mAdapter);
		grid1.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				// TODO Auto-generated method stub
				MainMenu menu = datas.get(arg2);
				// UIHelper.startActivitys(getActivity(), menu);

			}
		});

	}

	public void initGrid4() {

		GridView grid1 = (GridView) _view.findViewById(R.id.grid4);

		final List<MainMenu> datas = new ArrayList<MainMenu>();
		datas.add(new MainMenu(21, "日销售报表"));
		datas.add(new MainMenu(21, "周销售报表"));
		datas.add(new MainMenu(21, "月销售报表"));
		datas.add(new MainMenu(21, "单品销售"));
		datas.add(new MainMenu(21, "系列销售"));

		MainGridAdapter mAdapter = new MainGridAdapter(getActivity(), datas);
		// grid1.setColumnCount(4);
		grid1.setAdapter(mAdapter);
		grid1.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				// TODO Auto-generated method stub
				MainMenu menu = datas.get(arg2);
				// UIHelper.startActivitys(getActivity(), menu);

			}
		});

	}
}
